import React from 'react';
import {
    View,
    Text,
    FlatList,
    TouchableOpacity,
    DeviceEventEmitter,
    Dimensions,
    Image,
} from 'react-native';
import NavigationBar from '../../common/NavigationBar';
import {BASE_URL} from '../../common/BASE_URL';
import HttpUtils from '../../expand/dao/HttpUtils';
import {Constant, StylesConstant} from '../../common/Constant';
import StorageUtil from '../../utils/StorageUtil';
import NavigationUtil from '../../navigators/NavigationUtil';
import Utils from '../../utils/Utils';
import GlobalStyles from '../../common/styles/GlobalStyles';
import {Tabs} from '@ant-design/react-native';
import ChooseReportType from './components/ChooseReportType'
import EnterpriseInfoForm from "./components/EnterpriseInfoForm";
import CaseInfoForm from "./components/CaseInfoForm";
import ToastUtil from '../../utils/ToastUtil';
import styles from './styles'


export default class EditPersonalInfoPage extends React.Component {
    constructor(props) {
        super(props);
        // 获取参数
        this.state = {
            isLoading: true, // list加载状态
            // 当事人信息
            caseLitigants: {},
        };
    }

    componentDidMount() {
        // this.loadData();
    }

    loadData() {
        const {tabIndex} = this.state;
        this.setState({
            isLoading: false,
        })
    }
    _handleChooseReportType(type){
        this.setState({
            reportType: type
        })
    }
    render() {
        const {navigation} = this.props;
        const {tabIndex,reportType} = this.state;
        return (
            <View style={GlobalStyles.pageContainer}>
                {/* 自定义顶部导航条 */}
                <NavigationBar
                    navigation={navigation}
                    headerBackTitle={'添加单位信息'}
                />
                <View style={{flex: 1}}>
                    {this._renderForm()}
                </View>
            </View>
        );
    }
    formDataChange(key,value){
        this.setState({
            [key]: value
        })
    }

    _renderForm(){
        return (
            <>
                <EnterpriseInfoForm ref={'infoForm'} onChange={(data)=>this.formDataChange('caseLitigants', data)}/>
                {this._renderBottomBtns()}
            </>
        )
    }
    _handeSaveData() {
        // this.form
        if(this.refs.infoForm){
            const flag  = this.refs.infoForm.validateForm()
            if(flag){
                //
                const data = this.state.caseLitigants
                console.log(data)
                DeviceEventEmitter.emit('addEnterpriseInfo', data)
                this.props.navigation.pop()
            }
        }

    }

    _renderBottomBtns(){
        return (
            <View style={styles.bottomBtnsPanel}>
                <TouchableOpacity
                    style={styles.submitBtn}
                    onPress={() => this._handeSaveData()}
                >
                    <Text style={styles.submitBtnText}>保存</Text>
                </TouchableOpacity>
            </View>
        )
    }

}
